import {fetchGoodDetailAPI} from "@/api/detailApi";

const actions = {
    /*  获取商品详情的action */
    async fetchGoodDetail(context, goods_id) {
        const {message} = await fetchGoodDetailAPI(goods_id)
        context.commit("updateGoodDetail", message)
    }
}
const mutations = {
    /*  更新商品详情的action */
    updateGoodDetail(state, goodDetail) {
        state.goodDetail = goodDetail
    },
    /* 更新商品数量的mutation */
    updateCount(state, count) {
        state.options[1].info = count
    }
}
const state = () => {
    return {
        // 商品详情
        goodDetail: {},
        // uni-goods-nav组件的配置项目
        options: [
            {
                icon: 'chat',
                text: '客服'
            }, {
                icon: 'cart',
                text: '购物车',
                info: 0
            }],
        buttonGroup: [
            {
                text: '加入购物车',
                backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
                color: '#fff'
            },
            {
                text: '立即购买',
                backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
                color: '#fff'
            }
        ],
    }
}

const getters = {}
export default {
    namespaced: true,
    actions,
    mutations,
    state,
    getters
}
